package com.nbsaas.boot.repository;

import com.nbsaas.boot.entity.KnowledgePoint;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface KnowledgePointRepository extends JpaRepository<KnowledgePoint, Long> {
    
    Page<KnowledgePoint> findByCategory(String category, Pageable pageable);
    
    Page<KnowledgePoint> findByLevel(Integer level, Pageable pageable);
    
    @Query("SELECT k FROM KnowledgePoint k WHERE " +
           "(:category IS NULL OR k.category = :category) AND " +
           "(:level IS NULL OR k.level = :level) AND " +
           "(:keyword IS NULL OR k.title LIKE %:keyword% OR k.content LIKE %:keyword%)")
    Page<KnowledgePoint> search(String category, Integer level, String keyword, Pageable pageable);
} 